﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ruoxian_novel
{
    public partial class WritingForm : Form
    {
        public WritingForm()
        {
            InitializeComponent();
        }

        private void WritingForm_Load(object sender, EventArgs e)
        {
            //我的写作 管理书籍 小说分类 下拉框绑定数据
            string sql = "select * from Fenlei";
            DataSet ds_fenlei = DBHelper.GetDataSet(sql);
            comboBox_wodeshuji_fenlei.DataSource = ds_fenlei.Tables[0];
            comboBox_wodeshuji_fenlei.ValueMember = "Fenlei";
            comboBox_wodeshuji_fenlei.DisplayMember = "Fenlei";
            //我的写作 管理书籍 小说状态 下拉框绑定数据
            sql = "select * from bookZhuangtai";
            DataSet ds_zhuangtai = DBHelper.GetDataSet(sql);
            comboBox_wodeshuji_zhuangtai.DataSource = ds_zhuangtai.Tables[0];
            comboBox_wodeshuji_zhuangtai.ValueMember = "bookZhuangtai";
            comboBox_wodeshuji_zhuangtai.DisplayMember = "bookZhuangtai";
            //我的写作 管理书籍 搜索结果 绑定数据
            sql = string.Format("select b.bookID,f.Fenlei bookFenlei,b.bookName,y.Name bookZuozhe,b.bookGengxin,z.bookZhuangtai bookZhuangtai,b.bookTime,b.bookJianjie,b.Fengjin from Books b,Fenlei f,Yonghu y,BookZhuangtai z where b.bookFenlei=f.FenleiID and b.bookZuozhe=y.Zhanghao and b.bookZhuangtai=z.bookZhuangtaiID and b.Fengjin='正常' and y.Zhanghao='{0}'", Yonghu.zhanghao);
            DataTable dt = DBHelper.GetDataTable(sql);
            DGV_wodeshuji.DataSource = dt;
            DGV_wodeshuji.Columns["bookID"].Visible = false;
            DGV_wodeshuji.Columns["bookZuozhe"].Visible = false;
            DGV_wodeshuji.Columns["bookTime"].Visible = false;
            DGV_wodeshuji.Columns["bookJianjie"].Visible = false;
            DGV_wodeshuji.Columns["Fengjin"].Visible = false;
        }

        private void button_wodeshuji_sousuo_Click(object sender, EventArgs e)
        {
            //我的写作 搜索
            string fenlei = comboBox_wodeshuji_fenlei.Text;
            string zhuangtai = comboBox_wodeshuji_zhuangtai.Text;
            string sousuo = textBox_wodeshuji_sousuo.Text;
            if (comboBox_wodeshuji_fenlei.Text == "全部")
            {
                fenlei = "%";
            }
            if (comboBox_wodeshuji_zhuangtai.Text == "全部")
            {
                zhuangtai = "%";
            }
            if (textBox_wodeshuji_sousuo.Text == "")
            {
                sousuo = "%";
            }
            string sql = string.Format("select b.bookID,f.Fenlei bookFenlei,b.bookName,y.Name bookZuozhe,b.bookGengxin,z.bookZhuangtai bookZhuangtai,b.bookTime,b.bookJianjie,b.Fengjin from Books b,Fenlei f,Yonghu y,BookZhuangtai z where b.bookFenlei=f.FenleiID and b.bookZuozhe=y.Zhanghao and b.bookZhuangtai=z.bookZhuangtaiID and f.Fenlei like '{0}' and z.bookZhuangtai like '{1}' and b.bookName like '%{2}%' and b.Fengjin='正常' and y.Zhanghao='{3}'", fenlei, zhuangtai, sousuo, Yonghu.zhanghao);
            DataTable dt = DBHelper.GetDataTable(sql);
            DGV_wodeshuji.DataSource = dt;
        }

        private void button_wodeshuji_Click(object sender, EventArgs e)
        {
            //显示我的书籍
            panel_wodexiezuo_shujiguanli.BringToFront();
            //我的写作 搜索
            string fenlei = comboBox_wodeshuji_fenlei.Text;
            string zhuangtai = comboBox_wodeshuji_zhuangtai.Text;
            string sousuo = textBox_wodeshuji_sousuo.Text;
            if (comboBox_wodeshuji_fenlei.Text == "全部")
            {
                fenlei = "%";
            }
            if (comboBox_wodeshuji_zhuangtai.Text == "全部")
            {
                zhuangtai = "%";
            }
            if (textBox_wodeshuji_sousuo.Text == "")
            {
                sousuo = "%";
            }
            string sql = string.Format("select b.bookID,f.Fenlei bookFenlei,b.bookName,y.Name bookZuozhe,b.bookGengxin,z.bookZhuangtai bookZhuangtai,b.bookTime,b.bookJianjie,b.Fengjin from Books b,Fenlei f,Yonghu y,BookZhuangtai z where b.bookFenlei=f.FenleiID and b.bookZuozhe=y.Zhanghao and b.bookZhuangtai=z.bookZhuangtaiID and f.Fenlei like '{0}' and z.bookZhuangtai like '{1}' and b.bookName like '%{2}%' and b.Fengjin='正常' and y.Zhanghao='{3}'", fenlei, zhuangtai, sousuo, Yonghu.zhanghao);
            DataTable dt = DBHelper.GetDataTable(sql);
            DGV_wodeshuji.DataSource = dt;
        }
    }
}
